<template>
  <div class="tab-control">
    <div v-for="(item,index) in titles"
         :key="item.id"
         class="tab-control-item"
         @click="itemClick(index)"
         :class="{active: index === currentIndex}">
      <span>{{item}}</span>
    </div>
  </div>
</template>

<script>
  export default {
    name: "TabControl",
    props: {
      // 传入的选项卡标题
      titles: {
        type: Array,
        default() {
          return [];
        }
      }
    },
    data() {
      return {
        currentIndex: 0 //当前选项卡的索引
      }
    },
    methods: {
      itemClick(index) {
        this.currentIndex = index
        this.$emit('tabClick',index)
      }
    }
  }
</script>

<style scoped>
  .tab-control {
    /*弹性布局*/
    display: flex;
    /*水平居中*/
    text-align: center;
    /*设置字体大小*/
    font-size: 14px;
  }

  .tab-control-item {
    /*都站1比例*/
    flex: 1;
    /*设置高度以及行高*/
    height: 40px;
    line-height: 40px;
  }

  /*处于活跃的选项卡样式类*/
  .active{
    /*文字颜色高亮*/
    color: var(--color-high-text);



  }
  .active span {
    /*设置底部边框*/
     border-bottom: 3px solid var(--color-tint);
  }

</style>